//c2,c3
using System;

abstract class Shape
{
    public abstract double CalculateArea();
    public abstract bool IsValid();
    public abstract void ShapeInfo();
}

// 长方形类
class Rectangle : Shape
{
    public double Length { get; }
    public double Width { get; }

    public Rectangle(double length, double width)
    {
        Length = length;
        Width = width;
    }

    public override double CalculateArea()
    {
        return Length * Width;
    }

    public override bool IsValid()
    {
        return Length > 0 && Width > 0;
    }

    public override void ShapeInfo()
    {
        Console.WriteLine("这是一个长方形，长：" + Length + " 宽：" + Width);
    }

}

// 正方形类
class Square : Shape
{
    public double Side { get; }

    public Square(double side)
    {
        Side = side;
    }

    public override double CalculateArea()
    {
        return Side * Side;
    }

    public override bool IsValid()
    {
        return Side > 0;
    }

    public override void ShapeInfo()
    {
        Console.WriteLine("这是一个正方形，边长：" + Side);
    }

}

// 三角形类
class Triangle : Shape
{
    public double SideA { get; }
    public double SideB { get; }
    public double SideC { get; }

    public Triangle(double a, double b, double c)
    {
        SideA = a;
        SideB = b;
        SideC = c;
    }

    public override double CalculateArea()
    {
        double s = (SideA + SideB + SideC) / 2;
        return Math.Sqrt(s * (s - SideA) * (s - SideB) * (s - SideC));
    }

    public override bool IsValid()
    {
        return SideA > 0 && SideB > 0 && SideC > 0 &&
               SideA + SideB > SideC &&
               SideB + SideC > SideA &&
               SideA + SideC > SideB;
    }

    public override void ShapeInfo()
    {
        Console.WriteLine("这是一个三角形，边长分别为：" + SideA + ", " + SideB + ", " + SideC);
    }

}

enum ShapeType
{
    Rectangle,
    Square,
    Triangle
}

class ShapeFactory
{
    Random random = new Random();
    public Shape CreateShape(ShapeType shapeType)
    {
        switch (shapeType)
        {
            case ShapeType.Rectangle:
                return new Rectangle(random.Next(1, 10), random.Next(1, 10));
            case ShapeType.Square:
                return new Square(random.Next(1, 10));
            case ShapeType.Triangle:
                double a = random.Next(1, 10);
                double b = random.Next(1, 10);
                double minC = Math.Abs(a - b) + 1;
                double maxC = a + b - 1;
                double c = random.Next((int)minC, (int)maxC + 1);
                return new Triangle(a, b, c);
            default:
                throw new ArgumentException("未知的形状类型");
        }
    }
}

class Program
{
    static void Main()
    {
        const int SHAPE_COUNT = 10;
        Shape[] shapes = new Shape[SHAPE_COUNT];
        double totalArea = 0;
        ShapeFactory shapeFactory = new ShapeFactory();

        Console.WriteLine("创建10个随机形状:");
        for (int i = 0; i < SHAPE_COUNT; i++)
        {
            Random random = new Random();
            ShapeType type = (ShapeType)random.Next(3);
            shapes[i] = shapeFactory.CreateShape(type);
            if (shapes[i].IsValid())
            {
                totalArea += shapes[i].CalculateArea();
                Console.WriteLine($"\n形状 {i + 1}:");
                shapes[i].ShapeInfo();
            }
            else
            {
                Console.WriteLine($"\n形状 {i + 1}: 非法形状");
            }
        }

        Console.WriteLine($"\n所有形状的面积之和: {totalArea:F2}");
    }
}